home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 22 / Commodore_Free_Issue_22_2008_Commodore_Computer_Club.d64 / t.b guide 7.2 < prev    next >
Text File  |  2023-02-26  |  12KB  |  396 lines

  1. u
  2.  
  3. In the Beginning CHAPTER 7 SECTION 2
  4. \Lord Ronin from Q-Link\
  5.  
  6.      Continued from Section 1
  7.  
  8. Line 90 is another one that may have
  9. given you trouble in the way I wrote
  10. it. Got the print command and the
  11. quote, there really is a space before
  12. the first left cursor movement,
  13. followed by the second left cursor
  14. then the symbol and then another left
  15. cursor.
  16.  
  17. 100 sets the time delay to be the same
  18. as line 50. 110 is the same as line
  19. 60. Line 120 is the same as 70. Line
  20. 130 simple tells the entire programme
  21. to start over again. The way the
  22. programme is laid out, the variable
  23. labels of TM and BL can be reused.
  24.  
  25. Line 40 is the left to right work
  26. horse of the programme, they Prints a
  27. space that will erase the previous
  28. symbol on the line, then print the
  29. symbol, and then does a left cursor
  30. over the symbol, getting ready to do
  31. the erase and print all over again.
  32.  
  33. Line 90 is the same except it is doing
  34. everything in the opposite direction.
  35. See how it is moved with the need of
  36. the extra erasures of the symbol to
  37. move delete and print.
  38.  
  39. OK when you have this working, feel
  40. free to save it. Feeling a bit
  41. experimental? Well then change the
  42. symbol, do this all in upper case for
  43. now. Tired of the speed that it moves,
  44. try altering the TM variable. One
  45. thing that I have the local group
  46. members do is to make a black spade go
  47. from left to right. But how about a
  48. red diamond going from right to left.
  49. No problem in changing the symbol, How
  50. to do the colour?
  51.  
  52. Well that takes retyping out the line,
  53. just need one more thing in the line.
  54. Need to press the control and 1 key
  55. for black. You will see a different
  56. graphic symbol show up. If not and you
  57. see the cursor turn black, you forgot
  58. to open the print statement by
  59. retyping the " symbol. Same for the
  60. diamond or heart, retype the line and
  61. add the control 3 and a symbol will
  62. appear, run the programme. Did you put
  63. them in the right place? If not play
  64. with it a while. Maybe you want to
  65. change the screen and border colour,
  66. make a line 22 that says ?"my
  67. animation" or something like that. We
  68. have covered the basics on how to do
  69. that. Save it if you wish, the thing
  70. is, that you have made it on your own.
  71. There is that thing moving back and
  72. forth on the screen, You did it! You
  73. have just programmed a visual thing.
  74.  
  75. Now we come to the INPUT command. A
  76. way to have the user interact with
  77. what you have written. If you went
  78. through my thing on programmes for the
  79. C=. You may have not fallen asleep on
  80. the Text Adventures part. Simple and
  81. easy early to learn Text Adventures,
  82. use INPUT as the way to have the
  83. player enter information for the game.
  84.  
  85. Lets new the computer and do the
  86. following from the book.
  87.  
  88. 10 INPUT A$
  89. 20 ?"you typed: ";A$
  90. 30 ?
  91. 40 GOTO10
  92.  
  93. That is simple and there are two
  94. things here that are new, Ill get to
  95. the input in a moment. That print
  96. command on line 30, what is it going
  97. to print? The answer is Nothing! As
  98. you see on the line there is nothing
  99. to print, so all it is going to do is
  100. drop one line down. Since this
  101. programme can be run over and over
  102. again, that space just separates what
  103. you have done from the next part. No
  104. matter what you type a word, a number,
  105. a gfx, a letter, as soon as you hit
  106. the return key what every you input,
  107. is output to the screen. Can you see
  108. at this time the use of the IF THEN
  109. with INPUT? I mean you write a
  110. question and IF the answer is wrong
  111. THEN the programme prints a nasty
  112. response? <VBESG>
  113.  
  114. Well the secret isn't a big one, you
  115. can see on the first line that there
  116. is a variable, this will be for the
  117. input. Line 20 prints out both the
  118. message and what you printed, just
  119. that simple. Putting it together with
  120. other things is where the "fun" enters
  121. the game. I'll add here that there are
  122. some people who dislike the input
  123. command. Also there is available some
  124. code to remove that question mark at
  125. the end of the input line when you run
  126. the programme. Seen it in action,
  127. never found my copy of that command
  128. after a move.
  129.  
  130. OK here is a more understandable use
  131. of the INPUT command, the following
  132. will convert standard Fahrenheit to
  133. Centigrade and the reverse. New the
  134. machine and lets start.
  135.  
  136. 1 REM TEMPERATURE CONVERSION PROGRAMME
  137. 5 ?"<clear/home>"
  138. 10 ?"convert from farhenheit or
  139. celsius (f/c)":INPUT a$
  140. 20 IFA$=""THEN 20
  141. 30 IFA$="F"THEN100
  142. 40 IFA$<>"C"THEN10
  143. 50 INPUT"ENTER DEGREES CELSIUS: ";C
  144. 60 F=(C*9)/5+32
  145. 70 ?C;" DEG. CELSIUS = "; F;" DEG.
  146. FAHRENHEIT"
  147. 80 ?
  148. 90 GOTO10
  149. 100 INPUT"ENTER DEGREES FAHRENHEIT:
  150. ";F
  151. 110 C=(F-32)*5/9
  152. 120 ? F;" DEG. FAHRENHEIT = ";C;" DEG.
  153. CELSIUS"
  154. 130 ?
  155. 140 GOTO10
  156.  
  157. A lot of work to do something an old
  158. calculator I had would do with a few
  159. pushes of the keys, but there is a lot
  160. to see here. I mean we are familiar to
  161. some degree with many of the
  162. components of presented commands, See
  163. variables, math work, print
  164. statements. Now lets hope that I wrote
  165. it down right from the book, as we are
  166. going into this one.
  167.  
  168. REM part we covered, doing that
  169. shifted/clear home as well, Line 10 is
  170. a little different, We have the
  171. familiar print statement The : to
  172. separate commands on a line, But now
  173. we have an INPUT statement, Creating
  174. the variable a$ which should be either
  175. a f or a c.
  176.  
  177. Lines 20-40 are a new thing, sure they
  178. are the IF THEN statements, but on
  179. line 20 there is something new those
  180. "", and no space between them. The
  181. line is saying that if a$ is nothing,
  182. (no key press), then go to line 20.
  183. Note here that I wrote it as go to
  184. line 20, in programming you do not
  185. have to write that go to part, just
  186. the line number. OK what is happening
  187. is that the programme is going to sit
  188. there and wait for you do type in the
  189. right thing, before it goes anywhere
  190. else.
  191.  
  192. Line 30 works if a$ is the f, inputted
  193. from the keyboard, ff so then the
  194. programme will jump to line 100. Ah
  195. here is a new one, Line 40 has the
  196. does not equal c part, reading the
  197. line says that if the input that the
  198. user does from the keyboard doesn't
  199. equal c, the programme goes back to
  200. line 10 saying printing for the (f/c),
  201. and maybe the user will understand
  202. what he is to type in for the input.
  203. Covers here the input of the variable
  204. c as well as rejecting all other non
  205. recognised inputs, done in just one
  206. line.
  207.  
  208. Line 50 is an input and takes the
  209. centigrade degrees making them into
  210. the variable c. Line 60 does the math
  211. for us, Line 70 prints out what the
  212. centigrade is in standard. Here you
  213. may need to alter this for spaces to
  214. have things line up correctly. Line 80
  215. is a print statement to move down one
  216. line. Line 90 takes it back to line 10
  217. to start over again. Line 100 is the
  218. same with the input for Fahrenheit,
  219. giving f as the variable. Line 110
  220. does the math, Line 120 prints out the
  221. variable as a number and the text,
  222. again here you may need to adjust for
  223. spacing. Line 130 does that drop down
  224. again and Line 140 sends the programme
  225. back to line 10 to start over again.
  226.  
  227. A few things need to be added at this
  228. point, you can change the words in the
  229. statements. As I am obviously not a
  230. fan of metric, I wrote mine as
  231. standard for Fahrenheit, and
  232. centigrade for Celsius, as that was
  233. the term I was taught for the metric
  234. measurement. Doesn't hurt a thing if
  235. it makes you more comfortable, if you
  236. feel like experimenting, try changing
  237. the colours of the text, the border
  238. and the screen. Be surprised at how
  239. that will change the look and feel of
  240. the programme. Now that go to Line 10
  241. on lines 90 and 140. Takes you back to
  242. the start of the input for the
  243. programme. What it will also do is
  244. keep making a space from the print
  245. line, and then print the first line
  246. over again on your screen. If you
  247. don't want a long list of that and the
  248. answers on your screen, change that
  249. goto 10 to goto 5. That line clears
  250. the screen and puts the cursor at row
  251. 0 column 0.
  252.  
  253. Sort of like input, we have GET. This
  254. one works with each key press. New the
  255. PC and type in.
  256.  
  257. 1 ?"<CLEAR/HOME>"
  258. 10 GETA$:IFA$=""THEN10
  259. 20 ?A$;
  260. 30 GOTO10
  261.  
  262. Run it and see what happens, ok I'll
  263. let you know now, but it is more fun
  264. to run it. <G> Each character from the
  265. keyboard you type shows up one by one
  266. on a single line. WHY? OK lets tear it
  267. apart. Got what happens in line 1 as
  268. the clear screen and start at the top
  269. left, Line 10 has a variable called a$
  270. and the if then statement. Also in
  271. that if then statement the "" placed
  272. together, A point to bring up for
  273. those that intend to use type in
  274. books, Font changes in the different
  275. books may confuse you to if there is
  276. or isn't a space between the quotes.
  277. Most of the time there isn't, but it
  278. can look like it on the book page. We
  279. have a new command called GET, What
  280. does it do? Pretty much as it says, it
  281. is going to GET something. In this
  282. example, It wants to GET the keyboard
  283. input, and won't move along, hmm as
  284. stubborn as me, till it GETs what it
  285. is looking for. That is why nothing
  286. happens till you press a key. Works
  287. that way for every time you press a
  288. key, patiently waiting for you to
  289. enter a something, but takes it only
  290. one character at a time. Once you
  291. press a key, the programme goes right
  292. to line 20, where it prints that
  293. character where it is the variable a$.
  294. Next is line 30 that loops it back to
  295. the start.
  296.  
  297. The reason that it prints the
  298. characters all in a line is the use of
  299. that ; symbol. Change that to , and
  300. you will have the characters in neat
  301. rows at the 4 tab points on the
  302. screen. Drop the , and or the ; and it
  303. just goes along the left edge of the
  304. screen. A simple programme that with a
  305. slight addition is how I have people
  306. type in their name or other
  307. information on the little intro
  308. screens I make from time to time for
  309. the club. Also basically the same way
  310. that callers do when they log into the
  311. BBS and type anything in the message
  312. bases.
  313.  
  314. The Commodore book thinks that you
  315. saved that previous temperature
  316. convention thing. They want to show
  317. you how to shorten the programme down
  318. a bit, so they show in the book that
  319. you can alter lines 10-40 from all
  320. those IF THEN statements to
  321.  
  322. 10 ? "Convert from Fahrenheit or
  323. Celsius (F/C)"
  324. 20 GET A$: IF A$ = "" THEN 20
  325. 40 IF A$ <> "C" THEN 20
  326.  
  327. I dig RPGames. Have done since 1978ce
  328. when I was in my late 20s, no idea how
  329. many dice I have rolled or how many
  330. times I have rolled them. Nice to know
  331. that the C= can do dice rolling, but
  332. how to do that? Step by step me
  333. laddieo. <G> New the system and lets
  334. do the following.
  335.  
  336. 10 FOR X=1TO10
  337. 20 ?RND(1),
  338. 30 NEXT
  339.  
  340. Well run that and you see a pair of
  341. columns of numbers less than 1. OK
  342. that RND thing is pretty much a random
  343. number generator, but there is more to
  344. it than that, if you saw the same
  345. information on your screen as mine,
  346. then it wouldn't be random would it?
  347. But that is rather useless for dice
  348. rolling. The book now wants you to
  349. change line 20 to read.
  350.  
  351. 20 ? 6*RND(1),
  352.  
  353. Well running that and you still have
  354. some weird numbers, but you do have
  355. something to the left of the decimal
  356. point. OK lets change line 20 again to
  357. read...
  358.  
  359. 20 ? INT(6*RND(1)),
  360.  
  361. Ah now we have solid numbers, But wait
  362. a moment 0-5 is not what we want for a
  363. D6. So change the line again to
  364. read...
  365.  
  366. 20 ? INT(6*RND(1))+1,
  367.  
  368. Yeah here we go, from 1-6 gamers you
  369. can change the 6 to be a 4, 8, 10, 12,
  370. 20, 30 and 100, Reflecting the
  371. different game dice. Really advanced
  372. stuff is using the KB GFX to show the
  373. numbers. I've seen animated bits of
  374. dice rolling, along loads of other
  375. pretty pretties on the screen. All
  376. comes from this little part.
  377.  
  378. INT(LOWER LIMIT+(UPPER-LOWER+1)
  379.  *RND(1))
  380.  
  381. Ah that is supposed to be on one line,
  382. i know that it doesn't make any sense
  383. looking like that and there is a thing
  384. that will be in the next section that
  385. will require you to use this part. So
  386. I'll put it out in that area.
  387.  
  388. You see the next area is where we make
  389. a guessing game. Simple but remember
  390. you are the one creating it, I'll go
  391. over the parts for us, and then we
  392. will do that weird line.
  393.  
  394.     Continued next month.
  395.  
  396.